<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;

class CleanDeletedNotifications extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'notifications:clean';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '清理软删除超过30天的通知';

    /**
     * Execute the console command.
     */
    public function handle()
    {
        $count = DB::table('notifications')
            ->whereNotNull('deleted_at')
            ->where('deleted_at', '<', now()->subDays(30))
            ->delete();
            
        $this->info("已清理 {$count} 条过期通知");
    }
}
